using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;

public class Inventory : MonoBehaviour {

    private Dictionary<ItemType, int> items = new Dictionary<ItemType, int>();

    public void AddItem(ItemType item)
    {
        this.items[item]++;
        this.UpdateItems();
    }

    public GUIText inventoryText;

	// Use this for initialization
	void Start () {
        this.InitializeItems();
	}

    private void InitializeItems()
    {
         ItemType[] items = (ItemType[])Enum.GetValues(typeof(ItemType));

         for (int i = 0; i < items.Length; i++)
         {
             this.items.Add(items[i], 0);
         }
         this.UpdateItems();
    }


    public bool UseItem(ItemType item)
    {
        if (this.items[item] > 0)
        {
            this.items[item]--;
            this.UpdateItems();
            return true;
        }
        else return false;
    }


    private void UpdateItems()
    {
        Debug.Log(this.items.Count);
        this.inventoryText.text = "Items within your inventory:\n";
        foreach (var item in this.items)
        {
            this.inventoryText.text += string.Format("{0}: {1}\n", item.Key, item.Value);
        }
    }



}
